﻿package framework.core;

import java.util.PropertyResourceBundle;
/**
 * @author Administrator
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class Config
{
	private static final String CONFIG_BUNDLE_NAME = "framework";

	//	oracle外键异常code
	public static final int ORACEL_FK_ERROR_CODE = 2292;

	private static PropertyResourceBundle _configBundle =
		(PropertyResourceBundle) PropertyResourceBundle.getBundle(
			CONFIG_BUNDLE_NAME);

	public static final String WEBSERVER_RESIN = "resin";
	public static final String WEBSERVER_WEBLOGIC = "weblogic";
	public static final String WEBSERVER_TOMCAT = "tomcat";
	public static final String WEBSERVER_WEBSPHERE = "websphere";

	private static String getString(String name) throws Exception
	{
		String s = _configBundle.getString(name);

		if (s == null)
		{
			throw new Exception(
				CONFIG_BUNDLE_NAME + ".properties [没有" + name + "参数]");
		}
		return s;
	}

	private static String getString(String name, String defaultValue)
	{
		try
		{
			return getString(name);
		} catch (Exception e)
		{
			return defaultValue;
		}
	}

	private static int getInt(String name) throws Exception
	{
		String s = _configBundle.getString(name);

		if (s == null)
		{
			throw new Exception(
				CONFIG_BUNDLE_NAME + ".properties [没有" + name + "参数]");
		}
		try
		{
			return Integer.parseInt(s);
		} catch (Exception e)
		{
			throw new Exception(
				CONFIG_BUNDLE_NAME + ".properties [参数格式不正确(应为整数型)]");
		}
	}

	private static int getInt(String name, int defaultValue)
	{
		try
		{
			return getInt(name);
		} catch (Exception e)
		{
			return defaultValue;
		}
	}

	private static double getDouble(String name) throws Exception
	{
		String s = _configBundle.getString(name);

		if (s == null)
		{
			throw new Exception(
				CONFIG_BUNDLE_NAME + ".properties [没有" + name + "参数]");
		}
		try
		{
			return Double.parseDouble(s);
		} catch (Exception e)
		{
			throw new Exception(
				CONFIG_BUNDLE_NAME + ".properties [参数格式不正确(应为浮点型)]");
		}
	}
	private static double getDouble(String name, double defaultValue)
	{
		try
		{
			return getDouble(name);
		} catch (Exception e)
		{
			return defaultValue;
		}
	}
	private static boolean getBoolean(String name) throws Exception
	{
		String s = _configBundle.getString(name);

		if (s == null)
		{
			throw new Exception(
				CONFIG_BUNDLE_NAME + ".properties [没有" + name + "参数]");
		}
		try
		{
			return Boolean.valueOf(s).booleanValue();
		} catch (Exception e)
		{
			throw new Exception(
				CONFIG_BUNDLE_NAME + ".properties [参数格式不正确(应为布尔型)]");
		}
	}
	private static boolean getBoolean(String name, boolean defaultValue)
	{
		try
		{
			return getBoolean(name);
		} catch (Exception e)
		{
			return defaultValue;
		}
	}
	//===项目配置===

	//Srv名称
	public static String getSrv() throws Exception
	{
		return getString("projectSrv");
	}

	//web路径
	public static String getWebPath() throws Exception
	{
		return getString("projectWebPath");
	}

	//错误页面
	public static String getErrorUrl() throws Exception
	{
		//return getFrameworkPath()
		//	+ getString("projectErrorUrl", "/framework_error.jsp");
		return getString("projectErrorUrl", "/framework_error.jsp");			
	}

	//生成xml的jsp文件路径
	public static String getXmlJspPath() throws Exception
	{
		//return getFrameworkPath()
		//	+ getString("projectXmlJspPath", "/framework_xml.jsp");
		return getString("projectXmlJspPath", "/framework_xml.jsp");
			
	}

	//登陆页面
	public static String getLoginUrl() throws Exception
	{
		//return getFrameworkPath()
		//	+ getString("projectLoginUrl", "/framework_login.jsp");
		return getString("projectLoginUrl", "/framework_login.jsp");			
	}

	//用户登陆上下文
	public static String getLoginContextClass()
	{
		return getString("projectLoginContextClass", null);
	}

	//framework路径
	public static String getFrameworkPath() throws Exception
	{
		return getString("projectFrameworkPath");
	}

	//===数据库配置===

	//数据库jdbc驱动类
	public static String getDBDriverClass()
	{
		return getString("dbDriverClass", "oracle.jdbc.driver.OracleDriver");
	}
	//数据源
	public static String getDBDataSource()
	{
		return getString("dbDataSource", null);
	}
	public static String getDevDBDataSource()
	{
		return getString("devDBDataSource", null);
	}
	//数据库url
	public static String getDBUrl()
	{
		return getString("dbUrl", null);
	}
	public static String getDevDBUrl()
	{
		return getString("devDBUrl", null);
	}
	//数据库用户
	public static String getDBUser() throws Exception
	{
		return getString("dbUser");
	}
	public static String getDevDBUser() throws Exception
	{
		return getString("devDBUser");
	}
	//数据库密码
	public static String getDBPassword() throws Exception
	{
		return getString("dbPassword");
	}
	public static String getDevDBPassword() throws Exception
	{
		return getString("devDBPassword");
	}

	// 开发人员验证码
	public static String getDevValidateCode() throws Exception
	{
		return getString("devValidateCode");
	}
	//===调试配置===

	//是否调试,default=false
	public static boolean isDebug()
	{
		return getBoolean("debugDebug", false);
	}

	//是否输入调试信息到屏幕
	public static boolean isDebugPrint()
	{
		return getBoolean("debugPrint", false);
	}

	//是否输入调试信息到log文件
	public static boolean isDebugLog()
	{
		return getBoolean("debugLog", false);
	}

	//===WEB服务器配置===
	public static String getWebServerType() throws Exception
	{
		return getString("webServerType");
	}

	//===数据格式配置===

	//货币显示格式
	public static String getFormatMoney()
	{
		return getString("formatMoney", "#,###.00");
	}
	//货币输入格式
	public static String getFormatMoneyInput()
	{
		return getString("formatMoneyInput", "####.00");
	}
	//价格显示格式
	public static String getFormatPrice()
	{
		return getString("formatPrice", "#,###.00");
	}
	//价格输入格式
	public static String getFormatPriceInput()
	{
		return getString("formatPriceInput", "####.00");
	}
	//数量显示格式
	public static String getFormatQty()
	{
		return getString("formatQty", "#,###.##");
	}
	//数量输入格式
	public static String getFormatQtyInput()
	{
		return getString("formatQtyInput", "####.##");
	}
	// 油品容积（升）
	public static String getFormatOilQtyLiter()
	{
		return getString("formatOilQtyLiter", "###0.00");
	}
	// 油品重量（吨） 
	public static String getFormatOilQtyTon()
	{
		return getString("formatOilQtyTon", "###0.000");
	}

	//===数据格式配置===
	//发消息Url
	public static String getMobileMsgUrl()
	{
		return getString(
			"URL",
			"http://211.136.105.38:8080/sms_ema/submit?enterpriseid=1497&accountid=014&pswd=1234");
	}
	//是否有代理
	public static String getIsHaveProxy()
	{
		return getString("isHaveProxy", "false");
	}
	//代理服务器地址
	public static String getProxyHost()
	{
		return getString("proxyHost", "192.168.0.12");
	}
	//代理服务器有端口
	public static String getProxyPort()
	{
		return getString("proxyPort", "8080");
	}
	//供应商配送提醒价格
	public static double getProvidePrice()
	{
		return getDouble("providePrice", -100);
	}

	public static String getCharsetName()
	{
		return getString("charsetName", "utf-8");
	}

	public static String getCustomerErrorUrl() throws Exception
	{
		//return getFrameworkPath()
		//	+ getString("projectCustomerErrorUrl", "utf-8");
		return getString("projectCustomerErrorUrl", "utf-8");
			
	}
	//域名
	public static String getDomainName()
	{
		return getString("domainName", "http://");
	}	
	
	// 电子邮件相关
	public static String getMailServer() throws Exception
	{
		return getString("mailServer");
	}
	public static String getMailFromAddr() throws Exception
	{
		return getString("fromAddr");
	}
	public static String getMailUser() throws Exception
	{
		return getString("mailUser");
	}
	public static String getMailPassword() throws Exception
	{
		return getString("mailPassword");
	}
	public static String getMailAuth() throws Exception
	{
		return getString("mailSMTPAuth");
	}
	
	
	//GS相关
	public static String getGSDownTime(String defVal) throws Exception
	{
	    return getString("gsDownTime",defVal);
	}
	public static String getGSIP() throws Exception
	{
	    return getString("gsIP");
	}
	public static String getGSPort() throws Exception
	{
	    return getString("gsPort");
	}
	public static String getGSContext() throws Exception
	{
	    return getString("gsContext");
	}
	public static String getGSSavePath() throws Exception
	{
	    return getString("gsSavePath");
	}
    public static String getOnce() throws Exception
    {
        return getString("gsOnce");
    }	
	
    public static String getAesKey() throws Exception
    {
        return getString("AES_KEY");
    }	
}